const {contentMod}=require('../mod/ContentMod.js');

module.exports.addContent=async function(Info){
  let data=await contentMod.create(Info);
  console.log(data);
}

module.exports.selectContent=async function({onenum,num}){
  let sumNum=await contentMod.countDocuments();
  let sumPage=Math.ceil(sumNum/onenum);
  let data=await contentMod.find().populate({
    path:'Fclass'
  }).limit(onenum-0).skip((num-1)*onenum);
  return {
    sumPage: sumPage,
    data: data
  };
}

module.exports.updates=async function(Info){
  let data=await contentMod.find(Info)
  return data;
}

module.exports.updateInfo=async function(Info){
  let data=await contentMod.updateOne({_id:Info._id},{aTitle:Info.aTitle,author:Info.author,Fclass:Info.Fclass,Content:Info.Content,img:Info.img,table:Info.table})
  console.log(data);
}

module.exports.deletes= async function(Info){
  let data=await contentMod.remove({_id:Info.id});
  console.log(data);
}

module.exports.classContent=async function(Info){
  let data=await contentMod.find({Fclass:Info.Fclass});
  return data;
}

